package com.example.demo.controller;


import com.example.demo.entity.ResultModel;
import com.example.demo.mapper.ScoreMapper;
import com.example.demo.service.ScoreService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("score")
public class ScoreController {
    public final ScoreMapper scoreMapper;

    @GetMapping("listScore")//Get的请求方式,获取全部学生
    public ResultModel list() {
        return ResultModel.ok(scoreMapper.selectScore());
    }

    @DeleteMapping("deleteScore/{/stuId}")
    public ResultModel deleteScore(@PathVariable Integer stuId){
        return ResultModel.ok(String.format("删除成功，受影响行数为 %d",scoreMapper.deleteScoreById(stuId)));
    }
    @PutMapping("saveScore") //增加学生
    public ResultModel add(Score score){
        Integer count = scoreMapper.saveScore(score);
        return ResultModel.ok(String.format("插入成功，返回受影响行数 %d",count));
    }
}
